package com.example.page;
import com.github.pagehelper.Page;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
/*
@description:
@ClassName PageResult
@author chen
@create 2025-07-15 12:26
@Version 1.0
*/
@Data
public class PageResult<T>
{
    /**
     * 页码
     */
    private int pageNum;

    /**
     * 每页的数量
     */
    private int pageSize;

    /**
     * 记录总数
     */
    private long total;

    private List<T> list;

    public static <T> PageResult<T> of(List<T> list)
    {
        PageResult<T> result = new PageResult<>();
        result.list = (List<T>) list;
        if(null != list && list.size() > 0)
        {
            if (list instanceof Page)
            {
                Page<?> pg = (Page<?>) list;
                result.total = pg.getTotal();
                result.setPageNum(pg.getPageNum());
                result.setPageSize(pg.getPageSize());
            } else
            {
                result.total = list.size();
            }
        }
        else
        {
            result.total = 0;
            result.setPageNum(0);
            result.setPageSize(0);
        }

        return result;
    }
}
